#include <stdio.h>
#include <stdlib.h>

static unsigned long curChain,maxChain,maxDigit;

static void digitDeal(unsigned digit)
{
    curChain++;
    if(curChain>maxChain)
    {
        maxChain=curChain;
        maxDigit=digit;

        //printf("maxChain is %d\nmaxDigit is %d\n",maxChain,maxDigit);
    }
    if((digit*2)<=1000000)
        digitDeal(digit*2);
    if(((digit-1)%3 == 0)&&(digit>4)&&( ((digit-1)/3)%2 ==1))
        digitDeal((digit-1)/3);
    curChain-=1;
}

int main()
{
    digitDeal(1);
    printf("maxChain is %d\nmaxDigit is %d\n",maxChain,maxDigit);
    return 0;
}
